package com.zhq.blog.manage.domain.fronted.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * @title:IndexController.java
 * @package com.zhq.blog.manage.domain.fronted
 * @author 张恒强
 * @date 2014年12月30日 下午4:24:09
 * @version V1.0
 */
@Controller
@Scope("prototype")
public class IndexController extends BaseController{
	@RequestMapping(value = {"/index","/",""})
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response){
		if(request.getAttribute("redirect_remember")!=null){
			Cookie userName = new Cookie("luna_name",request.getAttribute("redirect_idorEmail").toString());
			userName.setPath("/");
			userName.setMaxAge(60 * 60 * 24 * 14);
			response.addCookie(userName);
			
			Cookie userpass = new Cookie("luna_password",context.getUserRepository().find_by_UserId(Long.parseLong(request.getAttribute("redirect_id").toString())).get(0).getPassword());
			userpass.setPath("/");
			userpass.setMaxAge(60 * 60 * 24 * 14);
			response.addCookie(userpass);
			
			Cookie c_remember = new Cookie("luna_remember",request.getAttribute("redirect_remember").toString());
			c_remember.setPath("/");
			c_remember.setMaxAge(60 * 60 * 24 * 14);
			response.addCookie(c_remember);
		}
		return buildModelView("/index",request);
	}
	
}
